package ace.module.product.core.impl.controller.rest.admin.ext;

import ace.cmp.core.model.R;
import ace.cmp.security.oauth2.resource.server.core.annotation.PreAuthorizeIsUserAuthenticated;
import ace.module.common.api.model.input.TenantInput;
import ace.module.product.api.model.input.PmsProductSaveInput;
import ace.module.product.core.impl.service.PmsProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商品基础资料 admin controller.
 *
 * @author Caspar
 */
@Tag(name = "商品基础资料-管理-租户-API")
@PreAuthorizeIsUserAuthenticated
@AllArgsConstructor
@RestController
@RequestMapping(PmsProductExtAdminController.PATH)
@Valid
public class PmsProductExtAdminController {

  public static final String PATH = "/product/pms-product";

  private final PmsProductService pmsProductService;

  @Operation(summary = "新增商品", description = "返回商品id")
  @PostMapping(value = "/admin/tenant/add")
  public R<Long> add(@Valid @NotNull @RequestBody TenantInput<PmsProductSaveInput> input) {
    Long id = this.pmsProductService.add(input);
    return R.ok(id);
  }
}